from rest_framework.permissions import BasePermission
from rest_framework_jwt.serializers import VerifyJSONWebTokenSerializer


class IsCommonAdminPermission(BasePermission):
    def has_permission(self, request, view):
        token = None
        token = request.META.get('HTTP_AUTHORIZATION')
        if token is None:
            return False
        valid_data = VerifyJSONWebTokenSerializer().validate(token)
        print(valid_data)
        user = valid_data['user']
        if user is None:
            return False
        else:
            if user.is_staff == 1:
                return True
            else:
                return False
